<?php
/**
 * QQAS - share your knowledge to the world!
 *
 * @author		xiaochong0302 <xiaochong0302@gmail.com>
 * @copyright	Copyright (c) 2011, Koogua Studio.
 * @license		http://www.qqas.org/user_guide/license.html
 * @link		http://www.qqas.org
 * @since		Version 1.0
 * @filesource
 */


/**
 * 后台控制器基类
 *
 */
class AdminAction extends Action
{

    protected $_User;
	protected $_admin;
	protected $_global;

	function _initialize()
	{

		$adminCookie  = cookie('admin');
		$adminSession = $_SESSION['admin'];
		if (empty($adminCookie) || empty($adminSession))
		{
			$this->redirect('Public/login');
		}
		
		$this->_global = F('cache_site_configs');
	    if (empty($this->_global))
	    {
	    	$Config = D('Config');
	    	$Config->updateConfigs();
	    }

		
        $name = $this->_global['software_registration_name'];
        $key = $this->_global['software_license_key'];
		$license = unserialize(kg_auth_code($key, 'decode', $name));
		$setupTime = $this->_global['site_setup_time'];

		$invalid = $overdue = false;

		if ($setupTime > time())
        {
            $invalid = true;
        }
		if (empty($key))
		{
		 	 if ($setupTime + 30 * 86400 < time())
		 	 {
		 	    $overdue = true;
		 	 }
		}
		else
		{
            if (false === strpos($license['domain'], $_SERVER['HTTP_HOST']))
            {
                $invalid = true;
            }
		}
        if ($invalid || $overdue)
        {
        	$this->redirect('Admin-Public/license');
        }

		$this->_User  = D('User');
		$this->_admin = $adminSession;
		$jsLangPackage = json_encode(L('js_lang_package'));

		$this->assign('_admin', $adminSession);
		$this->assign('_global', $this->_global);
		$this->assign('jsLangPackage', $jsLangPackage);
		$this->assign('waitSecond', 3);
		$this->assign('jumpUrl', $_SERVER['HTTP_REFERER']);
	}

}
// End Class

/* End of file AdminAction.class.php */
/* Location: ./App/Lib/Action/AdminAction.class.php */